#include<iostream>
using namespace std;
#include<vector>
#include<unordered_map>
class Solution {
public:
    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
        unordered_map<int, int> ma;
        for (auto& e : arr1)
            ++ma[e];
        int now = 0;
        for (auto& e : arr2)
            while (ma[e]--)
                arr1[now++] = e;
        for (auto& e : ma)
            while (e.second-->0)
                arr1[now++] = e.first;
        return arr1;
    }
};
int main() {
    vector<int> arr1{ 2,3,1,3,2,4,6,7,9,2,19 }, arr2{ 2,1,4,3,9,6 };
    Solution().relativeSortArray(arr1, arr2);
}